/*
 * File:   F08.h
 * Author: jcrada
 *
 * Created on 30 May 2011, 12:16 PM
 */

#ifndef ECB_CEC10_F08_H
#define	ECB_CEC10_F08_H

#include "ecb/benchmarks/cec10/CecProblem.h" 

#include "ecb/benchmarks/cec10/CecMath.h"
#include "ecb/operator/Permuted.h"
#include "ecb/operator/Grouped.h"
#include "ecb/operator/Shifted.h"
#include "ecb/benchmarks/cec10/CecRotated.h"
#include "ecb/function/Rosenbrock.h"
#include "ecb/function/Sphere.h"

namespace ecb{
    namespace cec10 {

        class F08 : public CecProblem {
        private:
            Function* rosenbrock, *sphere;
        public:

            F08(int dimensions, int mValue)
            : CecProblem("F08", "Single-group Shifted m-dimensional Rosenbrock's Function", dimensions,
            -100, 100, true, mValue, new CecRandom(8l)) {

                std::vector<scalar> shift = CecMath::ShiftVector(dimensions, _properties->getMinimum(), _properties->getMaximum() - 1.0,
                        randomizer());
                std::vector<int> permutation = CecMath::PermutationVector(dimensions, randomizer());
                std::vector<scalar> permutedShift(dimensions, 0);
                for (int i = 0; i < dimensions; ++i) {
                    permutedShift[i] = shift[permutation[i]];
                }

                rosenbrock = new Permuted(permutation, new Grouped(0, mValue,
                        new Shifted(permutedShift, 0, new Rosenbrock())));

                sphere = new Permuted(permutation, new Grouped(mValue, dimensions,
                        new Shifted(permutedShift, mValue, new Sphere())));
            }

            ~F08() {
                delete sphere;
                delete rosenbrock;
            }

            scalar f(const std::vector<scalar>& x) {
                return rosenbrock->f(x) * 1e6 + sphere->f(x);
            }
        };
    }
}

#endif	/* ECB_CEC10_F08_H */

